package com.markerhub.mapper;

import com.markerhub.common.vo.ClassVO;
import com.markerhub.common.vo.ClassmateVO;
import com.markerhub.entity.ManagerStudent;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.markerhub.entity.TeachingStudentInClass;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface ManagerStudentMapper extends BaseMapper<ManagerStudent> {
    List<String> getStudentNamesByStudentIds(@Param("studentIds") List<Integer> studentIds);

    void deleteByClassId(Integer classId);

    void saveAll(@Param("newStudents")List<TeachingStudentInClass> newStudents);

    List<ManagerStudent> selectByIds(@Param("studentIds") List<Integer> studentIds);


    void batchUpdateStatus(@Param("studentIds") List<Integer> studentIds, @Param("status") String status);


    @Select("SELECT " +
            "CASE WHEN is_first = '1' THEN '新生' ELSE '老生' END as type, " +
            "COUNT(*) as count " +
            "FROM m_manager_student " +
            "GROUP BY is_first")
    List<Map<String, Object>> selectStudentDistribution();

    @Select("SELECT COUNT(DISTINCT ms.id) " +
            "FROM m_manager_student ms " +
            "JOIN m_teaching_student_in_class cs ON ms.id = cs.student_id " +
            "JOIN m_manager_class c ON  c.id=cs.class_id  " +
            "WHERE c.teacher_id = #{teacherId}")
    int countTeacherStudents(@Param("teacherId") Long teacherId);

    @Select("SELECT ms.* FROM m_manager_student ms " +
            "JOIN m_teaching_student_in_class cs ON ms.id = cs.student_id " +
            "WHERE cs.class_id = #{classId}")
    List<ManagerStudent> selectClassStudents(@Param("classId") Integer classId);




}

